"""
使用统计法来计算⚪的面积
"""
import random

import math
import numpy as np


def statistic_method(total_num):
    total = 100000000
    x = np.array([random.random() for _ in range(total)])
    y = np.array([random.random() for _ in range(total)])
    z = x * x + y * y
    z[z < 1] = 1
    z[z > 1] = 0
    #  for
    print(4 * sum(z) / total)


def method2(total_num):
    res = 1
    for i in range(1, total_num):
        ...
        res += pow(-1, i) * 1 / (i * 2 + 1)


def lamanujin(total_num):
    ...
    x = 0
    for k in range(0, 10):
        x = x + (2 * math.sqrt(2) / 9801) * (
            math.factorial(4 * k) * (1103 + 26390 * k)
        ) / (math.pow(math.factorial(k), 4) * math.pow(396, 4 * k))
        print(k)
        print(1 / x)
    value = 1 / x
    print(value)


lamanujin(total_num)
total_num = 100000000
